# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# aim:    
# author: wangkaixuan
# email:  26554189525@qq.com 
# date:   2018/1/10

from sqlalchemy import Column,String,create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

base = declarative_base()
class User(base):
    __tablename__ = 'user_test'
    id = Column(String(20),primary_key=True)
    name = Column(String(20))

def add_data():
    new_user = User(id='3', name='cgr')
    session.add(new_user)

engine = create_engine('mysql+mysqlconnector://iroan:iroanMYS47@localhost:3306/mysql')
DBSession = sessionmaker(bind=engine)
session = DBSession()
# add_data()
user = session.query(User).filter(User.id == '2').one()
print('type:',type(User))
print('name:',user.name)
session.commit()
session.close()
